<?php


namespace app\admin\struct;


trait ShopStruct
{
    /**
     * 店铺结构体
     * @param array $request
     * @return int[]
     * @author ran
     * @date 2021-09-16 16:35
     * mailbox 466180170@qq.com
     */
    public function createShopResourceStruct(array $request): array
    {
        return [
            'shop_id' => getUniqueShopNumberCode(14),
            'shop_name' => (string)$request['shopName'],
            'shop_phone' => (string)$request['shopPhone'],
            'deptno' => (string)$request['deptno'],
            'shop_owner' => (string)$request['shopOwner'],
            'type' => (int)$request['type'],
            'type_name' => (string)$request['typeName'],
            'sex' => (string)$request['sex'],
            'password' => (string)$request['password'],
            'shop_mobile' => (string)$request['shopMobile'],
            'bed_num' => (int)$request['bedNum'],
            'reason' => (string)$request['reason'],
            'market_id' => (int)$request['marketId'],
            'market_name' => (string)$request['marketName'],
            'region_id' => (int)$request['regionId'],
            'region_name' => (string)$request['regionName'],
            'area' => (int)$request['area'],
            'status' => (int)$request['status'],
            'province_id' => (int)$request['provinceId'],
            'city_id' => (int)$request['cityId'],
            'country_id' => (int)$request['countryId'],
            'address' => (string)$request['address'],
            'introduce' => (string)($request['introduce'] ?? ''),
            'keycode' => (string)$request['keycode'],
            'remark' => (string)($request['remark'] ?? ''),
            'start_time' => (string)$request['startTime'],
            'end_time' => (string)$request['endTime'],
            'monthly_fee' => (string)$request['monthlyFee'],
            'close_end_at' => (string)$request['closeEndAt'],
            'close_start_at' => (string)$request['closeStartAt'],
            'open_at' => (string)$request['openAt'],
        ];
    }

    /**
     * 更新店铺结构体
     * @param array $request
     * @return int[]
     * @author ran
     * @date 2021-09-16 16:35
     * mailbox 466180170@qq.com
     */
    public function updateShopResourceStruct(array $request): array
    {
        return [
            'shop_id' => (string)$request['shopId'],
            'shop_name' => (string)$request['shopName'],
            'shop_phone' => (string)$request['shopPhone'],
            'deptno' => (string)$request['deptno'],
            'shop_owner' => (string)$request['shopOwner'],
            'type' => (int)$request['type'],
            'type_name' => (string)$request['typeName'],
            'sex' => (string)$request['sex'],
            'password' => (string)$request['password'],
            'shop_mobile' => (string)$request['shopMobile'],
            'bed_num' => (int)$request['bedNum'],
            'reason' => (string)$request['reason'],
            'market_id' => (int)$request['marketId'],
            'market_name' => (string)$request['marketName'],
            'region_id' => (int)$request['regionId'],
            'region_name' => (string)$request['regionName'],
            'area' => (int)$request['area'],
            'status' => (int)$request['status'],
            'province_id' => (int)$request['provinceId'],
            'city_id' => (int)$request['cityId'],
            'country_id' => (int)$request['countryId'],
            'introduce' => (string)($request['introduce'] ?? ''),
            'keycode' => (string)$request['keycode'],
            'remark' => (string)($request['remark'] ?? ''),
            'start_time' => (string)$request['startTime'],
            'end_time' => (string)$request['endTime'],
            'monthly_fee' => (string)$request['monthlyFee'],
            'close_end_at' => (string)$request['closeEndAt'],
            'close_start_at' => (string)$request['closeStartAt'],
            'open_at' => (string)$request['openAt'],
        ];
    }

    /**
     * @param $arr
     * @param array $needApiExceptKey
     * @return array
     * @author ran
     * @date 2021-10-18 21:59
     * mailbox 466180170@qq.com
     */
    public function returnShopResourceStructList($arr, array $needApiExceptKey = []): array
    {
        $apiArr = [];
        foreach ($arr as $value) {
            $apiArr[] =
                [
                    'shopId' => $value['shop_id'],
                    'shopName' => $value['shop_name'],
                    'shopPhone' => $value['shop_phone'],
                    'shopOwner' => $value['shop_owner'],
                    'shopMobile' => $value['shop_mobile'],
                    'marketName' => $value['market_name'],
                    'regionName' => $value['region_name'],
                    'status' => $value['status'],
                ];
        }
        return exceptMoreArrKey($apiArr, $needApiExceptKey);
    }

    /**
     * @param $arr
     * @param array $needApiExceptKey
     * @return array
     * @author ran
     * @date 2021-10-18 21:59
     * mailbox 466180170@qq.com
     */
    public function returnShopResourceStructArr($arr, array $needApiExceptKey = []): array
    {
        $apiReturn = [
            'shopId' => $arr['shop_id'],
            'shopName' => $arr['shop_name'],
            'deptno' => $arr['deptno'],
            'shopPhone' => $arr['shop_phone'],
            'typeName' => $arr['type_name'],
            'shopOwner' => $arr['shop_owner'],
            'marketName' => $arr['market_name'],
            'regionName' => $arr['region_name'],
            'shopMobile' => $arr['shop_mobile'],
            'status' => $arr['status'],
            'address' => $arr['address'],
            'openAt' => $arr['open_at'],
            'remark' => $arr['remark'],
            'keycode' => $arr['keycode'],
            'area' => $arr['area'],
            'monthlyFee' => $arr['monthly_fee'],
            'sex' => $arr['sex'],
            'startTime' => $arr['start_time'],
            'endTime' => $arr['end_time']
        ];
        return exceptArrKey($apiReturn, $needApiExceptKey);
    }
}